<template>
<!--  <h2>我的收藏</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="档案内容" prop="daContent">
        <el-input
          v-model="queryParams.daContent"
          placeholder="请输入检索关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" ref="refbut">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete"  @click="handeleDelete"  v-hasPermi="['archive:myCollect:remove']">移除</el-button>
      </el-col>
    </el-row>

    <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id"/>
      <el-table-column label="档案内容" prop="daContent" align="center" />
      <el-table-column label="档号" prop="daNum" align="center" />
      <el-table-column label="是否有电子件" prop="isEfile" align="center"></el-table-column>
      <el-table-column label="是否有实体件" prop="isEntity" align="center"></el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import {deleteMyCollection, getMyCollection} from "@/api/archive/liyong/myCollection";

export default {
  name: "index",
  mixins: [estimateTableHeight], // 混入方法
  data() {
    return {
      loading: true,
      dataList: [],
      total: 0,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getMyCollection(this.queryParams).then(response=>{
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    table_index(index){
      return (this.queryParams.pageNum-1) * this.queryParams.pageSize + index + 1;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handeleDelete(row) {
      const id = row.id || this.ids
      if(id.length == 0) {
        this.$message({ message: '请选择至少一条数据进行移除', type: 'warning' });
      } else {
        this.$modal.confirm('是否确认删除选中所选数据项？').then(function () { }).then(() => {
          deleteMyCollection(id.toString()).then(res => {
            if (res.code == "200") {
              this.$modal.msgSuccess("删除成功");
              this.getList();
            }
          })
        }).catch(() => { });
      }
    }
  }
}
</script>

<style scoped>

</style>
